package com.googlecode.lohr.parser.combinators.matcher.common;


import com.googlecode.lohr.parser.combinators.MatchError;
import com.googlecode.lohr.parser.combinators.matcher.MatchContext;
import com.googlecode.lohr.parser.combinators.matcher.Matcher;
import com.googlecode.lohr.parser.combinators.node.StringNode;

public class BooleanMatcher
extends Matcher
{
	static final String T= "true";
	static final String F= "false";
	
	@Override
	public void match(MatchContext ctx, int start) 
	{
		String input= ctx.getInput();
		String s= null;
		if (start < input.length())
		{
			String string= input.substring(start);
			if (string.startsWith(T)) {
				s= T;
			}
			else if (string.startsWith(F))
				s= F;
		}

		if (s == null) {
			ctx.matchError(this, start, new MatchError("Expected 'true' or 'false'", start));
		}
		else {
			StringNode node= new StringNode(this, start, start+s.length(), s);
			ctx.matchFound(this, start, node);
		}
		ctx.matchComplete(this, start);
	}
	
	@Override
	public String getLabel()
	{
		return "boolean";
	}
}
